package com.baidu.mapapi;

import android.content.ContentResolver;
import android.content.Context;
import android.content.IntentFilter;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Proxy;
import android.net.Uri;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.telephony.CellLocation;
import android.telephony.NeighboringCellInfo;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;

public class Mj
{
  private static b N;
  private static Method O;
  private static Method P;
  private static Class<?> Q;
  static e a = null;
  static final MKLocationManager b = new MKLocationManager();
  static int c = 2;
  static MapView d = null;
  static a e = null;
  static MapActivity f = null;
  static int g;
  static int h;
  static int i;
  static float j;
  static boolean k;
  static boolean l;
  static int m;
  static final Uri n;
  private static Handler o = null;
  private static Context p = null;
  private static String q;
  private static String r;
  private static String s;
  private static String t;
  private static String u;
  private final long A;
  private final long B;
  private List<NeighboringCellInfo> C;
  private long D;
  private long E;
  private int F;
  private int G;
  private int H;
  private int I;
  private int J;
  private int K;
  private List<ScanResult> L;
  private List<ScanResult> M;
  private Handler R;
  private Runnable S;
  private TelephonyManager v = null;
  private WifiManager w = null;
  private g x = null;
  private g y = null;
  private String z;

  static
  {
    g = 0;
    h = 0;
    i = 0;
    j = 1F;
    q = "";
    r = "";
    s = "";
    t = "";
    u = "";
    m = -1;
    N = null;
    O = null;
    P = null;
    Q = null;
    try
    {
      System.loadLibrary("BMapApiEngine");
      n = Uri.parse("content://telephony/carriers/preferapn");
      return;
    }
    catch (UnsatisfiedLinkError localUnsatisfiedLinkError)
    {
      Log.d("BMapApiEngine", "BMapApiEngine library not found!");
      Log.d("BMapApiEngine", localUnsatisfiedLinkError.getLocalizedMessage());
    }
  }

  Mj(BMapManager paramBMapManager, Context paramContext)
  {
    this.A = 3L;
    this.B = 3L;
    this.C = null;
    this.D = 0L;
    this.E = 0L;
    this.F = 0;
    this.G = 0;
    this.H = 0;
    this.I = 0;
    this.J = 0;
    this.K = 0;
    this.L = null;
    this.M = null;
    this.R = new Handler();
    this.S = new j(this);
    p = paramContext;
    c();
  }

  public static native int DisableProviderCC(int paramInt);

  public static native int EnableProviderCC(int paramInt);

  public static native Bundle GetGPSStatus();

  public static native Bundle GetMapStatus();

  public static native Bundle GetNoitifyInternal();

  public static native int InitLocationCC();

  public static native int InitMapControlCC(int paramInt1, int paramInt2);

  public static native int MapProc(int paramInt1, int paramInt2, int paramInt3);

  public static native int MsgMapProc(int paramInt1, int paramInt2, int paramInt3, int paramInt4);

  public static native void SetCellData(int paramInt1, int paramInt2, int paramInt3, int paramInt4, String paramString1, String paramString2, String paramString3);

  public static native void SetCellInfo(int paramInt1, int paramInt2, int paramInt3, int paramInt4, String paramString);

  public static native void SetLocationCoordinateType(int paramInt);

  public static native int SetNoitifyInternal(int paramInt1, int paramInt2);

  public static native int SetProxyInfo(String paramString, int paramInt);

  public static native void SetUpdateWifi(String paramString);

  public static native void UpdataGPS(double paramDouble1, double paramDouble2, float paramFloat1, float paramFloat2, float paramFloat3, int paramInt);

  public static void changeGprsConnect()
  {
    NetworkInfo localNetworkInfo = ((ConnectivityManager)p.getSystemService("connectivity")).getActiveNetworkInfo();
    if ((localNetworkInfo != null) && (localNetworkInfo.isAvailable()))
    {
      if (!(localNetworkInfo.getTypeName().toLowerCase().equals("wifi")))
        break label137;
      if (1 != m)
        break label56;
      SetProxyInfo(null, 0);
    }
    while (true)
    {
      while (true)
      {
        label56: String str1;
        do
        {
          while (true)
          {
            while (true)
            {
              String str3;
              do
              {
                do
                  return;
                while (m != 0);
                str3 = h();
              }
              while (str3 == null);
              if (!(str3.toLowerCase().contains("wap")))
                break;
              String str4 = Proxy.getDefaultHost();
              int i2 = Proxy.getDefaultPort();
              if (str4 == null)
                str4 = "10.0.0.172";
              if (i2 == -1)
                i2 = 80;
              SetProxyInfo(str4, i2);
            }
            SetProxyInfo(null, 0);
          }
          label137: str1 = localNetworkInfo.getExtraInfo();
        }
        while (str1 == null);
        if (!(str1.toLowerCase().contains("wap")))
          break;
        String str2 = Proxy.getDefaultHost();
        int i1 = Proxy.getDefaultPort();
        if (str2 == null)
          str2 = "10.0.0.172";
        if (i1 == -1)
          i1 = 80;
        SetProxyInfo(str2, i1);
      }
      SetProxyInfo(null, 0);
    }
  }

  private int e()
  {
    int i1;
    try
    {
      Q = Class.forName("android.telephony.cdma.CdmaCellLocation");
      O = Q.getMethod("getBaseStationId", new Class[0]);
      P = Q.getMethod("getNetworkId", new Class[0]);
      i1 = 0;
      return i1;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      i1 = -1;
    }
  }

  private static void f()
  {
    String str1 = g();
    if (str1 != null)
      if (str1.toLowerCase().contains("wap"))
      {
        String str2 = Proxy.getDefaultHost();
        int i1 = Proxy.getDefaultPort();
        if (str2 == null)
          str2 = "10.0.0.172";
        if (i1 == -1)
          i1 = 80;
        SetProxyInfo(str2, i1);
      }
    while (true)
    {
      while (true)
      {
        return;
        SetProxyInfo(null, 0);
      }
      SetProxyInfo(null, 0);
    }
  }

  private static String g()
  {
    String str;
    NetworkInfo localNetworkInfo = ((ConnectivityManager)p.getSystemService("connectivity")).getActiveNetworkInfo();
    if ((localNetworkInfo != null) && (localNetworkInfo.isAvailable()))
      if (localNetworkInfo.getTypeName().toLowerCase().equals("wifi"))
        if (1 == m)
          str = null;
    while (true)
    {
      while (true)
      {
        while (true)
        {
          return str;
          if (m != 0)
            break label74;
          str = h();
        }
        str = localNetworkInfo.getExtraInfo();
      }
      label74: str = null;
    }
  }

  public static native Bundle getNewBundle(int paramInt1, int paramInt2, int paramInt3);

  private static String h()
  {
    String str;
    ContentResolver localContentResolver = p.getContentResolver();
    Uri localUri = n;
    String[] arrayOfString = new String[3];
    arrayOfString[0] = "_id";
    arrayOfString[1] = "apn";
    arrayOfString[2] = "type";
    Cursor localCursor = localContentResolver.query(localUri, arrayOfString, null, null, null);
    localCursor.moveToFirst();
    if (localCursor.isAfterLast())
      str = null;
    while (true)
    {
      return str;
      str = localCursor.getString(1);
    }
  }

  public static native int initSearchCC();

  public static native void nativeDone();

  public static native void nativeInit();

  public static native void nativeRender();

  public static native void nativeResize(int paramInt1, int paramInt2);

  public static native void renderBaiduMap(Bitmap paramBitmap);

  public static native void renderCalDisScreenPos(Bundle paramBundle);

  public static native void renderFlsScreenPos(Bundle paramBundle);

  public static native void renderUpdateScreen(short[] paramArrayOfShort, int paramInt1, int paramInt2);

  public static native int sendBundle(Bundle paramBundle);

  public static native void sendPhoneInfo(Bundle paramBundle);

  public native int InitMapApiEngine();

  public void JNI_MapcallBackProc(int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    a locala = new a(this);
    locala.a = paramInt1;
    locala.b = paramInt2;
    locala.c = paramInt3;
    locala.d = paramInt4;
    Message localMessage = o.obtainMessage(1, 1, 1, locala);
    if (localMessage != null)
      o.sendMessage(localMessage);
  }

  public void JNI_callBackProc(int paramInt1, int paramInt2, int paramInt3)
  {
    switch (paramInt1)
    {
    default:
    case 506:
    case 5000:
    case 9:
    case 505:
    case 8020:
    case 10007:
    case 10009:
    case 10005:
    case 10001:
    case 10002:
    case 10003:
    case 10004:
    case 10006:
    }
    while (true)
    {
      do
        while (true)
        {
          do
            while (true)
            {
              do
                while (true)
                {
                  do
                    while (true)
                    {
                      do
                        while (true)
                        {
                          return;
                          d();
                        }
                      while (a == null);
                      a.a(paramInt1, paramInt2, paramInt3);
                    }
                  while (d == null);
                  d.a(paramInt1, paramInt2, paramInt3);
                }
              while (this.x == null);
              MKEvent localMKEvent2 = new MKEvent(paramInt1 - 10000, paramInt2, paramInt3);
              this.x.a(localMKEvent2);
            }
          while (b == null);
          b.c();
        }
      while (this.y == null);
      MKEvent localMKEvent1 = new MKEvent(paramInt1 - 10000, paramInt2, paramInt3);
      this.y.a(localMKEvent1);
    }
  }

  public Bundle J_GetDevInfo(int paramInt)
  {
    Bundle localBundle = new Bundle();
    switch (paramInt)
    {
    default:
    case 1:
    case 2:
    case 3:
    case 4:
    }
    while (true)
    {
      while (true)
      {
        while (true)
        {
          while (true)
          {
            return localBundle;
            localBundle.putString("im", q);
          }
          localBundle.putString("is", r);
        }
        localBundle.putString("mb", s);
        localBundle.putString("os", "Android_" + t);
        localBundle.putInt("cx", g);
        localBundle.putInt("cy", h);
        localBundle.putInt("xd", i);
        localBundle.putInt("yd", i);
      }
      localBundle.putString("na", u);
    }
  }

  public native int SetCacheDirectoryCC(String paramString);

  public native int StartApiEngineCC(String paramString);

  public native int StopApiEngineCC();

  public native int UnInitMapApiEngine();

  void a(MKSearchListener paramMKSearchListener)
  {
    this.y = new h(paramMKSearchListener);
  }

  boolean a()
  {
    int i1;
    f();
    N = new b();
    IntentFilter localIntentFilter = new IntentFilter();
    localIntentFilter.addAction("android.net.wifi.STATE_CHANGE");
    localIntentFilter.addAction("android.net.wifi.WIFI_STATE_CHANGED");
    localIntentFilter.addAction("android.net.wifi.SCAN_RESULTS");
    p.registerReceiver(N, localIntentFilter, null, null);
    if (b != null)
    {
      this.E = 0L;
      this.M = null;
      this.K = 0;
      this.J = 0;
      b.a();
      UpdataGPS(0D, 0D, 0F, 0F, 0F, 0);
      SetCellData(0, 0, 0, 0, null, null, null);
      if (k)
        b.enableProvider(0);
      if (l)
        b.enableProvider(1);
    }
    this.R.postDelayed(this.S, 1000L);
    if (StartApiEngineCC(this.z) == 0)
      i1 = 0;
    while (true)
    {
      return i1;
      i1 = 1;
    }
  }

  boolean a(String paramString, MKGeneralListener paramMKGeneralListener)
  {
    int i1;
    if (paramMKGeneralListener != null)
      this.x = new f(paramMKGeneralListener);
    this.z = paramString;
    if (a == null)
      a = new e(p);
    if (p != null)
    {
      if (this.v == null)
        this.v = ((TelephonyManager)p.getSystemService("phone"));
      if (this.w == null)
        this.w = ((WifiManager)p.getSystemService("wifi"));
      if ((this.w != null) && (this.w.isWifiEnabled()))
        this.w.startScan();
    }
    o = new Handler(this)
    {
      public void handleMessage()
      {
        Mj.a locala = (Mj.a)paramMessage.obj;
        Mj.MsgMapProc(locala.a, locala.b, locala.c, locala.d);
        super.handleMessage(paramMessage);
      }
    };
    if (initClass(new Bundle(), 0) == 0)
      i1 = 0;
    while (true)
    {
      while (true)
      {
        return i1;
        if (InitMapApiEngine() != 0)
          break;
        i1 = 0;
      }
      i1 = 1;
    }
  }

  boolean b()
  {
    int i1;
    if (N != null)
    {
      p.unregisterReceiver(N);
      N = null;
    }
    this.R.removeCallbacks(this.S);
    if (b != null)
      b.b();
    if (StopApiEngineCC() == 0)
      i1 = 0;
    while (true)
    {
      return i1;
      i1 = 1;
    }
  }

  void c()
  {
    DisplayMetrics localDisplayMetrics;
    if (p != null)
    {
      u = p.getFilesDir().getAbsolutePath();
      if (this.v == null)
        this.v = ((TelephonyManager)p.getSystemService("phone"));
      if (this.v != null)
      {
        q = this.v.getDeviceId();
        r = this.v.getSubscriberId();
        s = Build.MODEL;
        t = Build.VERSION.SDK;
      }
      Display localDisplay = ((WindowManager)p.getSystemService("window")).getDefaultDisplay();
      g = localDisplay.getWidth();
      h = localDisplay.getHeight();
      localDisplayMetrics = new DisplayMetrics();
      localDisplay.getMetrics(localDisplayMetrics);
      j = localDisplayMetrics.density;
      int i1 = Integer.parseInt(Build.VERSION.SDK);
      Log.e("sdkVersion", String.valueOf(i1));
      if (i1 <= 3)
        break label191;
    }
    try
    {
      i = Class.forName("android.util.DisplayMetrics").getField("densityDpi").getInt(localDisplayMetrics);
      label191: return;
    }
    catch (Exception localException)
    {
      while (true)
      {
        localException.printStackTrace();
        i = 160;
      }
      i = 160;
    }
  }

  boolean d()
  {
    String str1;
    String str2;
    String str3;
    String str4;
    int i1;
    String str6;
    CellLocation localCellLocation;
    if (a == null)
      i1 = 0;
    while (true)
    {
      return i1;
      if (this.v == null)
        this.v = ((TelephonyManager)p.getSystemService("phone"));
      if (this.v == null)
        break;
      long l2 = System.currentTimeMillis() / 1000L;
      if (l2 - this.E > 3L)
      {
        localCellLocation = this.v.getCellLocation();
        this.E = l2;
        if ((localCellLocation == null) || (!(localCellLocation instanceof GsmCellLocation)))
          break;
        GsmCellLocation localGsmCellLocation = (GsmCellLocation)localCellLocation;
        this.I = localGsmCellLocation.getCid();
        if (this.I < 0)
          this.I = 0;
        this.H = localGsmCellLocation.getLac();
        if (this.H < 0)
          this.H = 0;
        String str8 = this.v.getNetworkOperator();
        if ((str8 != null) && (str8.length() > 0))
        {
          if (str8.length() >= 3)
            this.F = Integer.valueOf(str8.substring(0, 3)).intValue();
          if (str8.length() >= 5)
            this.G = Integer.valueOf(str8.substring(3, 5)).intValue();
        }
      }
      if (this.w == null)
        this.w = ((WifiManager)p.getSystemService("wifi"));
      if ((this.w == null) || (!(this.w.isWifiEnabled())))
        break;
      long l1 = System.currentTimeMillis() / 1000L;
      if (l1 - this.D > 3L)
      {
        this.w.startScan();
        this.L = null;
        this.D = l1;
      }
      this.L = this.w.getScanResults();
      if ((this.L == null) || (this.L.size() <= 0))
        SetUpdateWifi("");
      if ((this.I <= 0) || (this.H < 0) || (this.F < 0))
        break;
      str1 = a.a(this.F, this.G, this.H, this.I, this.C, "");
      if (str1.length() <= 0)
        break;
      str2 = str1;
      if ((this.L == null) || (this.L.size() <= 0))
        break;
      a.a(this.L);
      String str5 = a.a(this.L, str1);
      if (str5.length() <= 0)
        break;
      SetUpdateWifi(str5);
      str6 = str5;
      String str7 = a.b(this.L, str5);
      if (str7.length() <= 0)
        break;
      str3 = str7;
      str4 = str6;
      if ((this.K != this.I) || (this.J != this.H) || (!(a.a(this.L, this.M))))
      {
        this.M = this.L;
        this.K = this.I;
        this.J = this.H;
        SetCellData(this.I, this.H, this.F, this.G, str2, str4, str3);
      }
      i1 = 1;
    }
    try
    {
      do
      {
        Object localObject2;
        do
        {
          Object localObject1;
          do
          {
            if ((Integer.parseInt(Build.VERSION.SDK) < 5) || ((Q == null) && (-1 == e())) || (!(Q.isInstance(localCellLocation))));
            localObject1 = O.invoke(localCellLocation, new Object[0]);
          }
          while (!(localObject1 instanceof Integer));
          this.I = ((Integer)localObject1).intValue();
          if (this.I < 0)
            this.I = 0;
          localObject2 = P.invoke(localCellLocation, new Object[0]);
        }
        while (!(localObject2 instanceof Integer));
        this.H = ((Integer)localObject2).intValue();
      }
      while (this.H >= 0);
      this.H = 0;
    }
    catch (Exception localException)
    {
      while (true)
      {
        while (true)
        {
          while (true)
          {
            while (true)
            {
              while (true)
              {
                while (true)
                {
                  while (true)
                  {
                    while (true)
                      localException.printStackTrace();
                    this.I = 0;
                    this.H = 0;
                    this.F = 0;
                    this.G = 0;
                  }
                  this.L = null;
                  SetUpdateWifi("");
                }
                str3 = "";
                str4 = str6;
              }
              str6 = "";
            }
            str3 = "";
            str4 = "";
          }
          str2 = "";
        }
        str1 = "";
        str2 = "";
      }
    }
  }

  public native int initClass(Object paramObject, int paramInt);

  class a
  {
    int a = 0;
    int b;
    int c;
    int d;
  }
}